#ifndef MUSICWINDOW_H
#define MUSICWINDOW_H

#include <QMainWindow>
#include<QFile>
#include<QDebug>
#include <QString>
#include <QTime>
#include<QMouseEvent>
#include<QStandardItemModel>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QDebug>
#include<QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include<QJsonArray>
#include<QSqlTableModel>
#include <QTableView>
#include <QStandardItemModel>
#include <QMediaPlayer>
#include<QMediaPlaylist>
#include <QFileDialog>
#include "videoplayer.h"
#include"lyricswindow.h"
#include"lyricslabel.h"
#include "my_database.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MusicWindow; }
QT_END_NAMESPACE

class MusicWindow : public QMainWindow
{
    Q_OBJECT

public:
    MusicWindow(QWidget *parent = nullptr);
    ~MusicWindow();

    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void parseJson_search(QByteArray byteArray);
    void parseJson_coverImg(QByteArray byteArray);
    static QString format_time(int milliseconds);
    void play_music(int index);
    void sequeIndex();
    void randomIndex();
    void updateIndex();
    // 加载本地资源（音乐或视频）
    void loadLocalFile();
    //设置播放列表
    void set_playlist(QString listName);
    //清空歌曲信息表
    void clearAll();
    //保存音乐信息到数据库
    void saveMusic(const QString &tableName,int index);
private slots:
    void on_pushButton_like_clicked(bool checked);
    void on_pushButton_switch_clicked(bool checked);

    void on_pushButton_volume_clicked(bool checked);

    void on_pushButton_mode_clicked();

    void on_pushButton_close_clicked();

    void on_pushButton_minsize_clicked();

    void on_pushButton_maxsize_clicked(bool checked);

    void on_pushButton_search_clicked();

    void replyFinished(QNetworkReply *reply);



    void positionChanged_slot(qint64 position);
    void durationChanged_slot(qint64 duration);
    void on_horizontalSlider_musicProgress_sliderReleased();

    void on_tableView_songs_clicked(const QModelIndex &index);

    void replyFinished2(QNetworkReply *reply);
    void on_pushButton_MV_clicked();

    void on_horizontalSlider_volume_sliderReleased();

    void on_pushButton_lastsong_clicked();

    void on_pushButton_nextsong_clicked();

    void on_label_albumPic_linkActivated();
    void on_listWidget_menu_currentRowChanged(int currentRow);

private:
    Ui::MusicWindow *ui;
    int currentMode; //播放模式
    bool mousePress;//鼠标按下标志
    QPoint  movePoint; //窗口移动距离
    QNetworkAccessManager *manager;
    QNetworkAccessManager *imgUrl_manager;
    QSqlTableModel *model;
    QStandardItemModel * pModel;
    QMediaPlaylist *playlist;
    QMediaPlayer *player;
    QList<unsigned int>songsId_list;//歌曲ID列表
    QStringList duration_list;//歌曲时长链表
    QStringList imgUrl_list;//专辑图片链表
    QStringList songName_list;//歌名
    QStringList singer_list;//歌手
    QStringList albumName_list;//专辑名列表
    QList<int>mvID_list;//MVID列表
    int mvid;//当前mvid
    unsigned int song_id;//当前歌曲ID
    int current_time;//当前歌曲播放时间
    VideoPlayer *mvPlayer;//mv播放窗体
    int current_index;//当前索引号
    QList<int> index_list; // 用于存储播放顺序的索引
    LyricsWindow *lyricsWindow;
    bool isPlayMV;//是否播放MV
    bool is_showLyric;//是否显示歌词
    my_database *recently_played;//最近播放数据
    my_database *my_favorite;//我的收藏
    QString sql;//封装sql语句操作
    QSqlQuery query;//用于记录sql
    QList<int>isLike_list;//是否收藏 1-收藏

};
#endif // MUSICWINDOW_H
